package com.haima.sage.bigdata.api.entity.api;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.haima.sage.bigdata.api.common.NameUtils;

public enum ResultType {
    Column("column", "col", "count", "value", "val"), Row("row"), List("list"), Page("page");

    //自定义字段
    private String[] values;

    //构造方法
    ResultType(String... values) {
        this.values = values;
    }

    @JsonValue
    public String[] getValue() {
        return values;
    }

    // 覆盖方法
    @Override
    public String toString() {
        return this.values[0];
    }

    @JsonCreator
    public static ResultType getInstance(String type) {
        type = NameUtils.trans(type);
        for (ResultType item : values()) {
            for (String value : item.getValue()) {
                String tmp = NameUtils.trans(value);
                if (tmp.equals(type)) {
                    return item;
                }
            }
        }
        return null;
    }
}
